<?php
error_reporting("E_ALL");ini_set("display_errors", 1);
header("content-Type: application/json; charset=utf-8");
include('alist.php');
$alist = new Alist;
$param=$_REQUEST;
if(empty($param['act']))$param['act']='';
if(!empty($param['s'])){
    $param['act']='down';
    $param['path']=$param['s'];
}
switch($param['act']){
    case "info":
    $info = $alist->getUserInfo();
    exit(json_encode($info));
    break;
    case "list":
    $path=!empty($param['path'])?$param['path']:'';
    $password=!empty($param['password'])?$param['password']:'';
    $page=!empty($param['page'])?$param['page']:'1';
    $per_page=!empty($param['per_page'])?$param['per_page']:'';
    $refresh=!empty($param['refresh'])?$param['refresh']:'false';
    $info = $alist->lists($path,$password,$page,$per_page,$refresh);
    exit(json_encode($info));
    break;
    case "get":
    $path=!empty($param['path'])?$param['path']:'';
    $password=!empty($param['password'])?$param['password']:'';
    $page=!empty($param['page'])?$param['page']:'1';
    $per_page=!empty($param['per_page'])?$param['per_page']:'';
    $refresh=!empty($param['refresh'])?$param['refresh']:'false';
    $info = $alist->get($path,$password,$page,$per_page,$refresh);
    exit(json_encode($info));
    break;
    case "down":
    $path=!empty($param['path'])?$param['path']:'';
    $password=!empty($param['password'])?$param['password']:'';
    $page=!empty($param['page'])?$param['page']:'1';
    $per_page=!empty($param['per_page'])?$param['per_page']:'';
    $refresh=!empty($param['refresh'])?$param['refresh']:'false';
    $info = $alist->get($path,$password,$page,$per_page,$refresh);
    if($info['code']==200){
        header('location:'.$info['data']['raw_url']);
    }else{
        exit(json_encode($info));
    }
    break;
}